﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.Web.Mvc.ModelBinding; 
using System.Web.Routing;
using System.Configuration;

using Pai.LiveStation.Data;

namespace Pai.LiveStation.Web
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        private static int stationID = -1;
        private static string stationName = "";

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);
            ModelBinderConfig.Initialize();
            GetStationInfo();
        }

        private void GetStationInfo()
        {
            stationName = ConfigurationManager.AppSettings["Station"];
            //using (RadioClassesDataContext dc = new RadioClassesDataContext())
            //{
            //    Station station = dc.Stations.Where(x => x.Name.Equals(stationName)).FirstOrDefault();
            //    if (station == null)
            //        throw new ArgumentException("No station with the name " + stationName + " exists.");
            //    stationID = station.ID;
            //}
            stationID = 1;
        }

        public static int StationID { get { return stationID; } }
        public static string StationName { get { return stationName; } }

    }
}